package com.tianji.learning.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.po.InteractionQuestion;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author hrz
 * @since 2025-08-29
 */
@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
public class InteractionQuestionController {

    private final IInteractionQuestionService questionService;

    @PostMapping
    @ApiOperation("新增问题")
    public void addQuestion(@Validated @RequestBody QuestionFormDTO questionFormDTO) {
        questionService.addQuestion(questionFormDTO);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改问题")
    public void updateQuestion(@Validated @RequestBody QuestionFormDTO questionFormDTO,
                               @PathVariable Long id) {
        questionService.updateQuestion(questionFormDTO, id);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询问题")
    public PageDTO<QuestionVO> pageQuestion(@RequestBody QuestionPageQuery questionPageQuery) {
        return questionService.pageQuestion(questionPageQuery);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询问题详情")
    public QuestionVO getQuestion(@PathVariable Long id) {
        return questionService.getQuestion(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除自己的问题")
    public void deleteQuestion(@PathVariable Long id){
        questionService.deleteQuestion(id);
    }
}
